<?php

namespace app\home\controller;

use think\facade\Request;
use app\home\model\Cartshop;

class Cart extends Base
{
    public  function getCartData()
    {
        $id = Request::param()['id'];

        $data = [];
        if (!empty($id)) {
            $data =  cartshop::alias('t1')->join('skate_spec_goods t2', 't1.goods_id = t2.id', 'left')->where('user_id', $id)->select();
        }
        $this->ok($data);
    }
    public function getOrder()
    {
        // $this->ok('aaaaa');
        $id = Request::param()['id'];
        $data = Cartshop::alias('t1')->join('skate_spec_goods t2', 't1.goods_id = t2.id', 'left')->where('user_id', $id)->where('is_se', 1)->select();
        $this->ok($data);
    }
    public function sdsds()
    {
        $param = Request::param();
        $res = Cartshop::where('goods_id', $param[0])->update(['is_se' => $param[1]]);
        if ($res) {
            $this->ok();
        } else {
            $this->fail();
        }
    }
    //删除购物车的物品
    public function cartSc()
    {
        $param = Request::param();
        // $this->ok($param);
        $user_id = $param['user_id'];
        $goods_id = $param['goods_id'];
        $data = \app\home\model\Cartshop::where(['user_id' => $user_id, 'goods_id' => $goods_id])->delete();
        $this->ok($data);
    }
    //点击提交按钮删除购物车表单里的数据
    public function tjorder()
    {
        $param = Request::param()[0];
        $data = \app\home\model\Cartshop::where(['user_id' => $param, 'is_se' => 1])->delete();
        $this->ok($param);
    }
}
